package com.zhang.boot.web.controller;

import com.zhang.boot.core.service.TestService;
import com.zhang.boot.core.util.UUIDUtil;
import com.zhang.boot.core.vo.rabbit.RabbitMessage;
import com.zhang.boot.web.config.RabbitConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
@Api(tags = "测试接口")
public class TestController {

    private final TestService testService;
    private final RabbitTemplate rabbitTemplate;

    @PostMapping("/testTransaction")
    @ApiOperation("测试事务")
    public void testTransaction() {
        testService.testTransaction();
    }

    @PostMapping("/testAsync")
    @ApiOperation("测试异步方法")
    public void testAsync() {
        testService.testAsync();
    }

    @PostMapping("/sendMsg")
    @ApiOperation("测试发送mq消息")
    public void sendMsg() {
        for (int i = 0; i < 10; i++) {
            RabbitMessage message = RabbitMessage.builder()
                    .messageId(UUIDUtil.fastUUID())
                    .messageType("TEST")
                    .messageContent("我是消息内容" + i)
                    .build();
            rabbitTemplate.convertAndSend(RabbitConfig.ORDER_EVENT_EXCHANGE, RabbitConfig.ORDER_CREATE_ORDER, message);
        }
    }

    /*@PostMapping("/hello/{name}")
    @ApiOperation("测试sentinel")
    public String hello(@PathVariable String name) {
        return testService.sayHello(name);
    }*/

}
